home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue59 / System / tar.txt next >
Encoding:
Text File  |  1996-10-06  |  13.1 KB  |  309 lines

  1. TAR Format
  2. Intel byte order
  3.  
  4. Information from File Format List 2.0 by Max Maischein.
  5.  
  6. --------!-CONTACT_INFO----------------------
  7. If you notice any mistakes or omissions, please let me know!  It is only
  8. with YOUR help that the list can continue to grow.  Please send
  9. all changes to me rather than distributing a modified version of the list.
  10.  
  11. This file has been authored in the style of the INTERxxy.* file list
  12. by Ralf Brown, and uses almost the same format.
  13.  
  14. Please read the file FILEFMTS.1ST before asking me any questions. You may find
  15. that they have already been addressed.
  16.  
  17.          Max Maischein
  18.  
  19. Max Maischein, 2:244/1106.17
  20. Max_Maischein@spam.fido.de
  21. corion@informatik.uni-frankfurt.de
  22. Corion on #coders@IRC
  23. --------!-DISCLAIMER------------------------
  24. DISCLAIMER:  THIS MATERIAL IS PROVIDED "AS IS".  I verify the information
  25. contained in this list to the best of my ability, but I cannot be held
  26. responsible for any problems caused by use or misuse of the information,
  27. especially for those file formats foreign to the PC, like AMIGA or SUN file
  28. formats. If an information it is marked "guesswork" or undocumented, you
  29. should check it carefully to make sure your program will not break with
  30. an unexpected value (and please let me know whether or not it works
  31. the same way).
  32.  
  33. Information marked with "???" is known to be incomplete or guesswork.
  34.  
  35. Some file formats were not released by their creators, others are regarded
  36. as proprietary, which means that if your programs deal with them, you might
  37. be looking for trouble. I don't care about this.
  38. --------------------------------------------
  39.  
  40. The Unix TAR program is an archiver program which stores files in a single
  41. archive without compression.
  42. OFFSET              Count TYPE   Description
  43. @section The Standard Format
  44. A @dfn{tar tape} or file contains a series of records.  Each record
  45. contains @code{RECORDSIZE} bytes.  Although this format may be
  46. thought of as being on magnetic tape, other media are often used.
  47.  
  48. Each file archived is represented by a header record which describes
  49. the file, followed by zero or more records which give the contents
  50. of the file.  At the end of the archive file there may be a record
  51. filled with binary zeros as an end-of-file marker.  A reasonable
  52. system should write a record of zeros at the end, but must not
  53. assume that such a record exists when reading an archive.
  54.  
  55. The records may be @dfn{blocked} for physical I/O operations.  Each
  56. block of @var{N} records (where @var{N} is set by the @samp{-b}
  57. option to @code{tar}) is written with a single @code{write()}
  58. operation.  On magnetic tapes, the result of such a write is a
  59. single tape record.  When writing an archive, the last block of
  60. records should be written at the full size, with records after the
  61. zero record containing all zeroes.  When reading an archive, a
  62. reasonable system should properly handle an archive whose last block
  63. is shorter than the rest, or which contains garbage records after a
  64. zero record.
  65.  
  66. The header record is defined in C as follows:
  67.  
  68. @example
  69. /*
  70.  * Standard Archive Format - Standard TAR - USTAR
  71.  */
  72. #define  RECORDSIZE  512
  73. #define  NAMSIZ      100
  74. #define  TUNMLEN      32
  75. #define  TGNMLEN      32
  76.  
  77. union record @{
  78.     char        charptr[RECORDSIZE];
  79.     struct header @{
  80.         char    name[NAMSIZ];
  81.         char    mode[8];
  82.         char    uid[8];
  83.         char    gid[8];
  84.         char    size[12];
  85.         char    mtime[12];
  86.         char    chksum[8];
  87.         char    linkflag;
  88.         char    linkname[NAMSIZ];
  89.         char    magic[8];
  90.         char    uname[TUNMLEN];
  91.         char    gname[TGNMLEN];
  92.         char    devmajor[8];
  93.         char    devminor[8];
  94.     @} header;
  95. @};
  96.  
  97. /* The checksum field is filled with this while the checksum is computed. */
  98. #define    CHKBLANKS    "        "        /* 8 blanks, no null */
  99.  
  100. /* The magic field is filled with this if uname and gname are valid. */
  101. #define    TMAGIC    "ustar  "        /* 7 chars and a null */
  102.  
  103. /* The magic field is filled with this if this is a GNU format dump entry */
  104. #define    GNUMAGIC  "GNUtar "        /* 7 chars and a null */
  105.  
  106. /* The linkflag defines the type of file */
  107. #define  LF_OLDNORMAL '\0'       /* Normal disk file, Unix compatible */
  108. #define  LF_NORMAL    '0'        /* Normal disk file */
  109. #define  LF_LINK      '1'        /* Link to previously dumped file */
  110. #define  LF_SYMLINK   '2'        /* Symbolic link */
  111. #define  LF_CHR       '3'        /* Character special file */
  112. #define  LF_BLK       '4'        /* Block special file */
  113. #define  LF_DIR       '5'        /* Directory */
  114. #define  LF_FIFO      '6'        /* FIFO special file */
  115. #define  LF_CONTIG    '7'        /* Contiguous file */
  116.  
  117. /* Further link types may be defined later. */
  118.  
  119. /* Bits used in the mode field - values in octal */
  120. #define  TSUID    04000        /* Set UID on execution */
  121. #define  TSGID    02000        /* Set GID on execution */
  122. #define  TSVTX    01000        /* Save text (sticky bit) */
  123.  
  124. /* File permissions */
  125. #define  TUREAD   00400        /* read by owner */
  126. #define  TUWRITE  00200        /* write by owner */
  127. #define  TUEXEC   00100        /* execute/search by owner */
  128. #define  TGREAD   00040        /* read by group */
  129. #define  TGWRITE  00020        /* write by group */
  130. #define  TGEXEC   00010        /* execute/search by group */
  131. #define  TOREAD   00004        /* read by other */
  132. #define  TOWRITE  00002        /* write by other */
  133. #define  TOEXEC   00001        /* execute/search by other */
  134. @end example
  135.  
  136. All characters in header records are represented by using 8-bit
  137. characters in the local variant of ASCII.  Each field within the
  138. structure is contiguous; that is, there is no padding used within
  139. the structure.  Each character on the archive medium is stored
  140. contiguously.
  141.  
  142. Bytes representing the contents of files (after the header record of
  143. each file) are not translated in any way and are not constrained to
  144. represent characters in any character set.  The @code{tar} format
  145. does not distinguish text files from binary files, and no
  146. translation of file contents is performed.
  147.  
  148. The @code{name}, @code{linkname}, @code{magic}, @code{uname}, and
  149. @code{gname} are null-terminated character strings.  All other
  150. fileds are zero-filled octal numbers in ASCII.  Each numeric field
  151. of width @var{w} contains @var{w}@minus{} 2 digits, a space, and a null,
  152. except @code{size}, and @code{mtime}, which do not contain the
  153. trailing null.
  154.  
  155. The @code{name} field is the pathname of the file, with directory
  156. names (if any) preceding the file name, separated by slashes.
  157.  
  158. The @code{mode} field provides nine bits specifying file permissions
  159. and three bits to specify the Set UID, Set GID, and Save Text
  160. (``stick'') modes.  Values for these bits are defined above.  When
  161. special permissions are required to create a file with a given mode,
  162. and the user restoring files from the archive does not hold such
  163. permissions, the mode bit(s) specifying those special permissions
  164. are ignored.  Modes which are not supported by the operating system
  165. restoring files from the archive will be ignored.  Unsupported modes
  166. should be faked up when creating or updating an archive; e.g. the
  167. group permission could be copied from the @code{other} permission.
  168.  
  169. The @code{uid} and @code{gid} fields are the numeric user and group
  170. ID of the file owners, respectively.  If the operating system does
  171. not support numeric user or group IDs, these fields should be
  172. ignored.
  173.  
  174. The @code{size} field is the size of the file in bytes; linked files
  175. are archived with this field specified as zero.
  176. @xref{Extraction Options}; in particular the @samp{-G} option.@refill
  177.  
  178. The @code{mtime} field is the modification time of the file at the
  179. time it was archived.  It is the ASCII representation of the octal
  180. value of the last time the file was modified, represented as an
  181. integer number of seconds since January 1, 1970, 00:00 Coordinated
  182. Universal Time.
  183.  
  184. The @code{chksum} field is the ASCII representation of the octal
  185. value of the simple sum of all bytes in the header record.  Each
  186. 8-bit byte in the header is added to an unsigned integer,
  187. initialized to zero, the precision of which shall be no less than
  188. seventeen bits.  When calculating the checksum, the @code{chksum}
  189. field is treated as if it were all blanks.
  190.  
  191. The @code{typeflag} field specifies the type of file archived.  If a
  192. particular implementation does not recognize or permit the specified
  193. type, the file will be extracted as if it were a regular file.  As
  194. this action occurs, @code{tar} issues a warning to the standard
  195. error.
  196.  
  197. @table @code
  198. @item LF_NORMAL
  199. @itemx LF_OLDNORMAL
  200. These represent a regular file.  In order to be compatible with
  201. older versions of @code{tar}, a @code{typeflag} value of
  202. @code{LF_OLDNORMAL} should be silently recognized as a regular
  203. file.  New archives should be created using @code{LF_NORMAL}.  Also,
  204. for backward compatibility, @code{tar} treats a regular file whose
  205. name ends with a slash as a directory.
  206.  
  207. @item LF_LINK
  208. This represents a file linked to another file, of any type,
  209. previously archived.  Such files are identified in Unix by each file
  210. having the same device and inode number.  The linked-to
  211. name is specified in the @code{linkname} field with a trailing null.
  212.  
  213. @item LF_SYMLINK
  214. This represents a symbolic link to another file.  The linked-to
  215. name is specified in the @code{linkname} field with a trailing null.
  216.  
  217. @item LF_CHR
  218. @itemx LF_BLK
  219. These represent character special files and block special files
  220. respectively.  In this case the @code{devmajor} and @code{devminor}
  221. fields will contain the major and minor device numbers
  222. respectively.  Operating systems may map the device specifications
  223. to their own local specification, or may ignore the entry.
  224.  
  225. @item LF_DIR
  226. This specifies a directory or sub-directory.  The directory name in
  227. the @code{name} field should end with a slash.  On systems where
  228. disk allocation is performed on a directory basis the @code{size}
  229. field will contain the maximum number of bytes (which may be rounded
  230. to the nearest disk block allocation unit) which the directory may
  231. hold.  A @code{size} field of zero indicates no such limiting.
  232. Systems which do not support limiting in this manner should ignore
  233. the @code{size} field.
  234.  
  235. @item LF_FIFO
  236. This specifies a FIFO special file.  Note that the archiving of a
  237. FIFO file archives the existence of this file and not its contents.
  238.  
  239. @item LF_CONTIG
  240. This specifies a contiguous file, which is the same as a normal
  241. file except that, in operating systems which support it,
  242. all its space is allocated contiguously on the disk.  Operating
  243. systems which do not allow contiguous allocation should silently treat
  244. this type as a normal file.
  245.  
  246. @item 'A' @dots{}
  247. @itemx 'Z'
  248. These are reserved for custom implementations.  Some of these are
  249. used in the GNU modified format, as described below.
  250. @end table
  251.  
  252. Other values are reserved for specification in future revisions of
  253. the P1003 standard, and should not be used by any @code{tar} program.
  254.  
  255. The @code{magic} field indicates that this archive was output in the
  256. P1003 archive format.  If this field contains @code{TMAGIC}, the
  257. @code{uname} and @code{gname} fields will contain the ASCII
  258. representation of the owner and group of the file respectively.  If
  259. found, the user and group ID represented by these names will be used
  260. rather than the values within the @code{uid} and @code{gid} fields.
  261.  
  262. @section GNU Extensions to the Archive Format
  263. The GNU format uses additional file types to describe new types of
  264. files in an archive.  These are listed below.
  265.  
  266. @table @code
  267. @item LF_DUMPDIR
  268. @itemx 'D'
  269. This represents a directory and a list of files created by the
  270. @samp{-G} option.  The @code{size} field gives the total size of the
  271. associated list of files.  Each filename is preceded by either a @code{'Y'}
  272. (the file should be in this archive) or an @code{'N'} (The file is a
  273. directory, or is not stored in the archive).  Each filename is
  274. terminated by a null.  There is an additional null after the last
  275. filename.
  276.  
  277. @item LF_MULTIVOL
  278. @itemx 'M'
  279. This represents a file continued from another volume of a
  280. multi-volume archive created with the @samp{-M} option.  The original
  281. type of the file is not given here.  The @code{size} field gives the
  282. maximum size of this piece of the file (assuming the volume does not
  283. end before the file is written out).  The @code{offset} field gives
  284. the offset from the beginning of the file where this part of the
  285. file begins.  Thus @code{size} plus @code{offset} should equal the
  286. original size of the file.
  287.  
  288. @item LF_VOLHDR
  289. @itemx 'V'
  290. This file type is used to mark the volume header that was given with
  291. the @samp{-V} option when the archive was created.  The @code{name}
  292. field contains the @code{name} given after the @samp{-V} option.
  293. The @code{size} field is zero.  Only the first file in each volume
  294. of an archive should have this type.
  295.  
  296. @end table
  297. EXTENSION:
  298. OCCURENCES:
  299. PROGRAMS:
  300. REFERENCE:
  301. SEE ALSO:
  302. VALIDATION:
  303. OFFSET              Count TYPE   Description
  304. 0000h                 256 byte   Other header info ?
  305. 0100h                   6 char   ID='ustar',0
  306. EXTENSION:TAR
  307. OCCURENCES:PC, Unix
  308. PROGRAMS:TAR
  309.